package com.opal.jx.controller;

import com.opal.consts.WSC;
import com.opal.domain.R;
import com.opal.jx.entity.JxAssessReception;
import com.opal.jx.entity.table.JxAssessBzcj;
import com.opal.jx.entity.table.JxPost;
import com.opal.jx.exception.JxAssessException;
import com.opal.jx.service.JxBZCJService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 包装车间
 */
@RestController
@RequestMapping("jx/bzcj")
public class JxBZCJController {

    @Autowired
    private JxBZCJService jxBZCJService;

    /**
     * 添加包装员工绩效数据
     * @param jxAssessReception
     * @return
     */
    @RequestMapping("addAssessData")
    public R addAssessData(@RequestBody JxAssessReception jxAssessReception){
        return jxBZCJService.addAssessDataService(jxAssessReception);
    }

    /**
     * 一线员工页面打开 与 按钮【考核页面】和【组长】触发此接口：初始化一线员工的数据
     * @param jxAssessReception
     * @return
     */
    @RequestMapping("selectJxAssessBzcj")
    public List<JxAssessBzcj> selectJxAssessBzcj(JxAssessReception jxAssessReception){
       return jxBZCJService.selectJxAssessBzcjService(jxAssessReception);
    }

    /**
     * 包装车间--一线员工页面按钮【组长】触发此接口：用于初始化此按钮的数据
     * @return
     */
    @RequestMapping("selectBZCJAllGroupLeader")
    public Object selectBZCJAllGroupLeader(JxAssessReception jxAssessReception){ //组织、部门、岗位名称
        return jxBZCJService.selectBZCJAllGroupLeader(jxAssessReception);
    }

    /**
     * 包装车间--获取辅助人员的数据:辅助人员、组长、清洁工、搬运工
     * @return {
     *     fuZhuRenYuan:[
     *         {empName:"测试一",empCode:"001",zuZhangName:"测试五",zhuGuanName:"x"......},
     *         {empName:"测试二",empCode:"002",zuZhangName:"测试五",zhuGuanName:"x"....},
     *         ],
     *     fuZhuZuZhang:[
     *         {empName:"测试五",empCode:"005",zuZhangName:"测试五",zhuGuanName:"x".....},
     *         {empName:"测试六",empCode:"006",zuZhangName:"测试六",zhuGuanName:"x"....},
     *     ],
     *     fuZhuZaGong:[
     *         {empName:"测试七",empCode:"007",zuZhangName:"测试七",zhuGuanName:"x"....},
     *     ],
     * }
     */
    @RequestMapping("selectBzcjFuZhuRenYuan")
    public Object selectBzcjFuZhuRenYuan(@RequestBody JxAssessReception jxAssessReception){
       return jxBZCJService.selectBzcjFuZhuRenYuanService(jxAssessReception);
    }

    @RequestMapping("addBzcjFuZhuRenYuan")
    @ResponseBody
    public Object addBzcjFuZhuRenYuan(@RequestBody JxAssessReception jxAssessReception){
        return jxBZCJService.addBzcjFuZhuRenYuanService(jxAssessReception);
    }

    @RequestMapping("saveZhuGuanAssessData")
    @ResponseBody
    public Object saveZhuGuanAssessData(@RequestBody JxAssessReception jxAssessReception){
        return jxBZCJService.saveZhuGuanAssessDataService(jxAssessReception);
    }
    /**
     *从绩效表中获取产线主管和辅助主管的数据和前端需要拼装的字段
     * @param year  年、月
     * @return columns字段和数值   [
     *         {
     *             "data":[ {empName: "方水珠",empCode:"0056825",postName:"产线主管",zuZhangName1:"800",zuZhangName2:"800",zuZhangName3:"800",zuZhangName4:"800",zuZhangName5:"800",
     *                 performanceBonus:"",attendanceRate:"",exceptionBonus:"",illegalFine:"",resultMoney:"",remarks:"",assessType:"" }],
     *             "columns":[
     *                 {"field": 'zuZhangName1', "title": '丘红云', "width": "5%","align": "center","editor": {"type":"textbox", "options": {"onChange":bzCxZhuGuanPerformanceBonus}}}
     *                 .....
     *             ]
     *         }
     *         .......
     *         ]
     */
    @RequestMapping("getBzcjZhuGuanJxAssess")
    @ResponseBody
    public Object getBzcjZhuGuanJxAssess(Integer year,Integer month){
        return jxBZCJService.getBzcjZhuGuanJxAssessService(year,month);
    }

    /**
     *从员工表中获取产线主管和辅助主管的数据
     * @param jxAssessReception  参数：年、月、部门（查员工表）、岗位名称二个
     * @return columns字段和数值   [
     *         {
     *             "data":[ {empName: "方水珠",empCode:"0056825",postName:"产线主管",zuZhangName1:"800",zuZhangName2:"800",zuZhangName3:"800",zuZhangName4:"800",zuZhangName5:"800",
     *                 performanceBonus:"",attendanceRate:"",exceptionBonus:"",illegalFine:"",resultMoney:"",remarks:"",assessType:"" }],
     *             "columns":[
     *                 {"field": 'zuZhangName1', "title": '丘红云', "width": "5%","align": "center","editor": {"type":"textbox", "options": {"onChange":bzCxZhuGuanPerformanceBonus}}}
     *                 .....
     *             ]
     *         }
     *         .......
     *         ]
     */
    @RequestMapping("selectJxEmpZhuGuanInfo")
    @ResponseBody
    public Object selectJxEmpZhuGuanInfo(JxAssessReception jxAssessReception){
        return jxBZCJService.selectBzcjZhuGuanByEmpService(jxAssessReception);
    }

    /**
     * 从员工表获取主管的数据
     * @param jxAssessReception
     * @return  同getBzcjZhuGuanJxAssess接口一致
     */
    @RequestMapping("selectBzcjZhuGuanByEmp")
    @ResponseBody
    public Object selectBzcjZhuGuanByEmp(@RequestBody JxAssessReception jxAssessReception){
        return jxBZCJService.selectBzcjZhuGuanByEmpService(jxAssessReception);
    }


    /**
     * 异常返回消息
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public R exceptionMessage(RuntimeException e){
        e.printStackTrace();
        if (e instanceof JxAssessException){    //自定义的异常
            return new R(WSC.PRECONDITIONFAILED,((JxAssessException) e).getMsg());
        }

        return new R(WSC.PRECONDITIONFAILED,e.getMessage());
    }

}
